package com.fzh.netty;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;

/**
 * Netty服务器业务逻辑
 * @author ZoharFang
 * @date 2016年8月31日
 */
public class EchoServerHandler extends SimpleChannelInboundHandler<String>{

	/**
	 * 捕获服务器的异常
	 */
	@Override
	public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
		cause.printStackTrace();
		ctx.close();
	}

	@Override
	protected void channelRead0(ChannelHandlerContext ctx, String msg) throws Exception {
		System.out.println("Server received: " + msg);
		ctx.writeAndFlush(msg);
	}

}
